﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NewKataminoSolver
{
    class KataminoGraph
    {
        public static Katamino _k;
        private int _Ww, _Wh; // Image window width and height
        private int _Mw, _Mh; // mapping/matrix width and height
        private int _sw, _sh; // discrete integer step in width and height
        private static Color[] palette = { Color.White,
                                      Color.Blue, Color.Red, Color.Green, Color.Brown, Color.Purple, Color.Orange,
                                      Color.LightBlue, Color.Pink, Color.LightGreen, Color.Yellow, Color.Violet, Color.Lime};
        private int[,] _c; // color map matrix.
        public Bitmap _bm;
        public Graphics _gr;

        public KataminoGraph(Katamino k, int w, int h)
        {
            _k = k;
            _Ww = k.ImageSize().Width;
            _Wh = k.ImageSize().Height;
            _bm = new Bitmap(_Ww, _Wh);
            _gr = Graphics.FromImage(_bm);
            _gr.Clear(Color.Salmon);
            // _k.pictureBox1.Image = _bm;
            _Mw = w;
            _Mh = h;
            _sw = (_Ww / w);
            _sh = (_Wh / h);
            _c = new int[h, w];
            for (int ih = 0; ih < h; ih++)
                for (int iw = 0; iw < w; iw++)
                    _c[ih, iw] = 0*(iw + ih) % 13; // fill mosaic

            for (int ih = 0; ih < h; ih++)
            {
                for (int iw = 0; iw < w; iw++)
                    Plot(_c[ih, iw], iw, ih);
            }
            _gr.Clear(Color.White);
        }
        public void DrawColorPentaAt(int c, Penta p, int iw, int ih)
        {
            for (int i = 0; i < p.x.Length; i++)
            {
                Plot(c, iw + p.x[i], ih + p.y[i]);
            }
        }

        public void Plot(int c, int iw, int ih)
        {
            _c[ih, iw] = c;
            Brush b = new SolidBrush(palette[c]);
            _gr.FillRectangle(b, _sw * iw, _sh * ih, _sw, _sh);
        }
    }
}
